package com.example.travel_front.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.travel_front.Model.Comment;
import com.example.travel_front.R;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.ViewHolder> {

    private final List<Comment> commentList;

    public CommentAdapter(List<Comment> commentList) {
        this.commentList = commentList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Comment comment = commentList.get(position);
        holder.username.setText(comment.getUsername());
        holder.content.setText(comment.getContent());
        holder.likes.setText(String.valueOf(comment.getLikes()));
        holder.comments.setText(String.valueOf(comment.getComments()));
        holder.timestamp.setText(comment.getTimestamp());
        Glide.with(holder.imgAvatar.getContext()).load(comment.getUserAvatar()).error(R.drawable.user).into(holder.imgAvatar);
    }

    @Override
    public int getItemCount() {
        return commentList.size();
    }

   static class ViewHolder extends RecyclerView.ViewHolder {
        TextView username, content, likes, comments, timestamp;
        ImageView imgAvatar;

        public ViewHolder(View view) {
            super(view);
            username = view.findViewById(R.id.topicUserName);
            content = view.findViewById(R.id.topicContent);
            likes = view.findViewById(R.id.txtTopicLikes);
            comments = view.findViewById(R.id.txtTopicComments);
            timestamp = view.findViewById(R.id.topicTimeStamp);
            imgAvatar = view.findViewById(R.id.imgTopicAvatar);
        }
    }


}

